if(PkgConfig_FOUND)
    pkg_check_modules(gtest_main QUIET IMPORTED_TARGET gtest_main)
    set(packages PkgConfig::gtest_main)
endif()

if (gtest_main_FOUND)
    file(GLOB SOURCE_FILES *.cpp)
    set(TEST_CASES)
    foreach(filename ${SOURCE_FILES})
        # build_case(${filename})
        get_filename_component(target ${filename} NAME_WE)
        add_executable(${target} ${filename})
        add_test(NAME ${target} COMMAND ${target})
        target_link_libraries(${target} PRIVATE ${packages})
        list(APPEND TEST_CASES ${target})
    endforeach()

    # 通过添加自定义目标，一次编译所有测试用例，用于执行ctest
    add_custom_target(tests ALL
        DEPENDS ${TEST_CASES})
else()
    get_filename_component(CURRENT_DIR_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
    message(STATUS "${packages} not found! Skipping ${CURRENT_DIR_NAME}")
endif()
